$(function() {
    jQuery.fn.center = function(loaded) {
        var obj = this;
        body_width = parseInt($(window).width());
        body_height = parseInt($(window).height());
        block_width = parseInt(obj.width());
        block_height = parseInt(obj.height());

        left_position = parseInt((body_width / 2) - (block_width / 2) + $(window).scrollLeft());
        if (body_width < block_width) {
            left_position = 0 + $(window).scrollLeft();
        };

        top_position = parseInt((body_height / 2) - (block_height / 2) + $(window).scrollTop());
        if (body_height < block_height) {
            top_position = 0 + $(window).scrollTop();
        };

        if (!loaded) {

            obj.css({
                'position': 'absolute'
            });
            obj.css({
                'top': ($(window).height() - $('#code').height()) * 0.5,
                'left': left_position
            });
            $(window).bind('resize', function() {
                obj.center(!loaded);
            });
            $(window).bind('scroll', function() {
                obj.center(!loaded);
            });

        } else {
            obj.stop();
            obj.css({
                'position': 'absolute'
            });
            obj.animate({
                'top': top_position
            }, 200, 'linear');
        }
    }
    
})


function Scroll(obj,speed,interval){ //父级容器，轮播速度，切换间隔
 $("."+obj).each(function(){
 var $box = $(this),
 $imgUl = $box.children(".imgList"),
 $imgLi = $imgUl.children("li"),
 $btnUl = $box.children(".btnList"),
 $btnLi = $btnUl.children("li"),
 $btnPreNex = $box.children(".pre-nex"),
 $btnPre = $box.children(".prev"),
 $btnNex = $box.children(".next"),
 n = $imgLi.length,
 width = $imgLi.width(),
 left = parseFloat($imgUl.css("left")),
 k = 0,
 Player;
 $imgUl.css("width",n*width);
 function scroll(){ //轮播事件
 $imgUl.stop().animate({left:-width},speed,function(){
  k += 1;
  $imgUl.css("left",0);
  $imgUl.children("li:first").appendTo($(this));
  $btnLi.removeClass('cur');
  if(k >= n){
  k = 0;
  }
  $btnUl.children("li").eq(k).addClass('cur'); 
 });
 }
 $btnLi.click(function(){ //小圆点点击事件
 var index = $btnLi.index(this); 
 $(this).addClass('cur').siblings("li").removeClass('cur');
 if(index >= k){
  var dif = index-k;
  left = -dif*width;
  $imgUl.stop().animate({left:left},speed,function(){
  $imgUl.css("left",0);
  $imgUl.children("li:lt("+dif+")").appendTo($imgUl); 
  });
 }
 else{
  var j = n-(k-index);
  $imgUl.css("left",(index-k)*width);
  $imgUl.children("li:lt("+j+")").appendTo($imgUl);
  $imgUl.stop().animate({left:0},speed); 
 }
 k = index;
 }); 
 $btnPreNex.click(function(){ //左右按钮点击事件
 var index = $btnLi.index(this); 
 if($(this).hasClass('next')){
  if(!$imgUl.is(":animated")){
  k += 1;
  $imgUl.animate({left:-width},speed,function(){
  $imgUl.css("left",0);
  $imgUl.children("li:first").appendTo($(this));
  if(k >= n){
  k = 0;
  }
  $btnUl.children("li").removeClass('cur').eq(k).addClass('cur');
  });
  }
 }
 else {
  if(!$imgUl.is(":animated")){
  k += -1;
  $imgUl.css("left",-width);
  $imgUl.children("li:last").prependTo($imgUl);
  $imgUl.stop().animate({left:0},speed);
  if(k < 0){
  k = n-1;
  }
  $btnUl.children("li").removeClass('cur').eq(k).addClass('cur');
  }
 }
 }); 
 $box.hover(  //鼠标移入、移出事件
 function(){
  clearInterval(Player);
  $btnPreNex.addClass('show');
 },
 function(){
  Player = setInterval(function(){scroll()},interval);
  $btnPreNex.removeClass('show');
 }
 );
 Player = setInterval(function(){scroll()},interval);
 });
 } 
 $(function () {  
 //Scroll("bannerCon",600,4000);
 });
 



function toAudit(id) {
	$("#recordId").val(id);
    $("#tj").show();
	var url = basePath+"/bus/index/toAudit?id="+id;
	$.ajax({
		type : "post",
		url : url,
		data : id,
		dataType : "json",
		success : function(data) {
			$("#bak").text("");
			if(data.code == 0){
			$("#planProgress").text(data.data.planProgress);
			$("#planPro").text(data.data.planPro);
			$("#reportDate2").text(data.data.reportDate);
			$("#targetPre").text(data.data.targetPre);
			$("#currentPro").text(data.data.currentPro);
			$("#accPro").text(data.data.accPro);
			$("#accPre").text(data.data.accPre);
			$("#proStatus").text(data.data.proStatus);
			$("#extDay").text(data.data.extDay);
			$("#extReason").text(data.data.extReason);
			$("#progressId").val(data.data.modelProcessId);
			$("#reviewRcdId").val(data.data.reviewRcdId);
			$("#modelCode2").text(data.data.modelCode);
			$("#bak").text(data.data.remark);
			//清空缓存图片
			$(".imgList").html("");
			$(".btnList").html("");
			$.each(data.data.annexDto,function(i, url) {
				var jq = url.path.lastIndexOf("."); 
			    var arr = url.path.substr(jq);
				var picList = ".jpg .JPEG .png .PNG .jpeg .JPG";
				var videoList = ".mp4 .MP4 .mov .MOV";
				var liList
				if(picList.indexOf(arr) >= 0){
					liList = "<li><a href='"+url.path+"' target='view_window'><img src='"+url.path+"' alt=''/></a></li>"
				}else if(videoList.indexOf(arr) >= 0){
					liList = "<li><a href='"+url.path+"' onclick='showOriginalVideo(this)' target='view_window'><video controls><source src='"+url.path+"' type='video/mp4' /></video></a></li>"
				}
				
				$(".imgList").append(liList);
				var _btn = "";
				if(i==0){
					_btn = "<li class='cur'><span></span></li>";
				}else{
					_btn = "<li><span></span></li>";
				}
				$(".btnList").append(_btn);
			});
			 Scroll("bannerCon",600,4000);//读取轮播事件
		}else{
			msgPrompt(data.message);
		}
		}
	});
    $("#advise").val(""); //清空原来输入的
}


function audit(){
	var recordId = $("#recordId").val();
	var result = $("#auditResult").val();
	var advise = $("#advise").val();
	var accPro = $("#accPro").html();
	var modelProgressId = $("#progressId").val();
	var reviewRcdId = $("#reviewRcdId").val();
	var extDay = $("#extDay").html();
	var proStatus = $("#proStatus").html();
	var auditResult = [];
	var data = {
			recordId : recordId,
			result : result,
			advise : advise,
			status : result,
			accPro : accPro,
			modelProgressId : modelProgressId,
			id : reviewRcdId,
			extDay : extDay,
			proStatus : proStatus
		};
	auditResult.push(data);
	var url = basePath+"/bus/index/audit";
	showLoad();
		$.ajax({
			type : "post",
			url : url,
			data : {auditData:JSON.stringify(auditResult)},
			dataType : "json",
			success : function(data) {
				msgPrompt(data.message);
				toIndex();
			}
		});
	}
//页面跳转
function toIndex(){
	var url = basePath+"/bus/index/index";
	window.location.href=basePath + '/bus/meter/returnMeterGive?url=' + basePath + '/bus/index/index&flg=meterList';
}

//弹出详细
function toView(recordId,recordDetailId){
    $("#advise").val("");
	var data = {
			recordId :recordId,
			recordDetailId : recordDetailId
	}
	var url = basePath+"/bus/prgview/toView";
	$.ajax({
		type : "post",
		url : url,
		data : data,
		dataType : "json",
		success : function(data) {
			if(data.code == 0){
			$("#planProgress").text(data.data.planProgress);
			$("#planPro").text(data.data.planPro);
			$("#rp").find("#reportDate2").text(data.data.reportDate);
			$("#targetPre").text(data.data.targetPre);
			$("#currentPro").text(data.data.currentPro);
			$("#accPro").text(data.data.accPro);
			$("#accPre").text(data.data.accPre);
			$("#proStatus").text(data.data.proStatus);
			$("#extDay").text(data.data.extDay);
			$("#extReason").text(data.data.extReason);
			$("#modelCode2").text(data.data.modelCode);
			$("#bak").text(data.data.remark);
			$("#ar").html(data.data.status);
			$("#tj").hide();
			//$("#auditStatus").text(data.data.status);
			$("#advise").val(data.data.advise);
			//清空缓存图片
			$(".imgList").html("");
			$(".btnList").html("");
			$.each(data.data.annexDto,function(i, url) {
				var jq = url.path.lastIndexOf("."); 
			    var arr = url.path.substr(jq);
				var picList = ".jpg .JPEG .png .PNG .jpeg .JPG";
				var videoList = ".mp4 .MP4 .mov .MOV";
				var liList
				if(picList.indexOf(arr) >= 0){
					liList = "<li><a href='"+url.path+"' target='view_window'><img src='"+url.path+"' alt=''/></a></li>"
				}else if(videoList.indexOf(arr) >= 0){
					liList = "<li><a href='"+url.path+"' onclick='showOriginalVideo(this)' target='view_window'><video controls><source src='"+url.path+"' type='video/mp4' /></video></a></li>"
				}
				$(".imgList").append(liList);
				var _btn = "";
				if(i==0){
					_btn = "<li class='cur'><span></span></li>";
				}else{
					_btn = "<li><span></span></li>";
				}
				$(".btnList").append(_btn);
			});
			 Scroll("bannerCon",600,4000);//读取轮播事件
		}else{
			msgPrompt(data.message);
		}
		}
	});
}